<?php

include 'confidential_settings.php';
// This include contains 5 variables:
//  - db_name: database name
//  - table_name_x: table name
//  - username: username
//  - password: password
//  - localhost: host name

$dbh=mysql_connect ($localhost, $username, $password) or die('Cannot connect to the database because: ' . mysql_error());

mysql_select_db ($db_name) or die(mysql_error()); 

$result = mysql_query("SELECT * FROM $table_name_gas WHERE DATE_SUB(CURDATE(),INTERVAL 2 DAY) <= DATE(date_entered)");

mysql_close($dbh);


mysql_data_seek ($result , 0);
 
$max = 0;
$nb = 0;
while($row = mysql_fetch_array($result)){
	$tmp = $row['val']*10;
	if($tmp > $max){
		$max = $tmp;
	}
	$nb = $nb + 1;
}

// fail save in case there is no max:
if($max == 0){
	$max = 1;
}

mysql_data_seek ($result , 0);

echo '<img src="http://chart.apis.google.com/chart?cht=lc&chd=t:';
while($row = mysql_fetch_array($result)){
	$tmp = ($row['val']*10)*100/$max;
	echo printf( "%.1f", $tmp );
	echo ',';
}
echo '0';
echo '&chs=600x500&chg=20,20&chxt=x,y&chxr=1,0,';
echo $nb;
echo '|1,0,';
echo $max;
echo '" />';

?>
